From 916122d7c43c0277748cd8aa8e4d3ecc3f7072b4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Thu, 8 Sep 2005 17:08:41 +0000 Subject: [PATCH] syncing up with core --- ChangeLog | 17 ++++ babl/base/Makefile.am | 2 + babl/base/babl-base.c | 2 + babl/base/type-float.c | 4 +- babl/base/type-u16.c | 51 ++++++------ babl/base/type-u32.c | 133 +++++++++++++++++++++++++++++++ babl/base/type-u8.c | 12 +-- extensions/CIE-Lab.c | 16 ++-- extensions/Makefile.in | 3 + tests/Makefile.am | 3 + tests/conversions.c | 172 +++++++++++++++++++++++++++++++++++++++++ 11 files changed, 374 insertions(+), 41 deletions(-) create mode 100644 babl/base/type-u32.c create mode 100644 tests/conversions.c diff --git a/ChangeLog b/ChangeLog index 0b9ed28..5871649 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2005-09-08 Øyvind Kolås + + * babl/base/type-float.c: + * babl/base/type-u16.c: + * babl/base/type-u8.c: s/"linear"/"plane"/ + * babl/base/Makefile.am, + * babl/base/babl-base.c, + * babl/base/type-u32.c: new type. + * extensions/CIE-Lab.c: + * extensions/Makefile.in: changes needed (for not yet added) lcms + extension. + * tests/Makefile.am: added new test. + * tests/conversions.c: new test to check fast paths against reference + fish. + 2005-09-08 Øyvind Kolås Made simple fishes work in the core. @@ -20,6 +35,7 @@ * babl/babl-introspect.c: (each_introspect): * babl/babl-model.c: (babl_model_new): * babl/babl-core.c: (babl_core_init): s/linear/plane/ + * tests/babl_class_name.c: update according to class changes. 2005-09-08 Øyvind Kolås @@ -32,6 +48,7 @@ registered data structures. * docs/graphics/Makefile.am: added web target, and .SILENT option. * docs/Makefile.am: added .SILENT option. + * configure.ac: added website location. 2005-09-01 Michael Schumacher diff --git a/babl/base/Makefile.am b/babl/base/Makefile.am index e58d545..56f4318 100644 --- a/babl/base/Makefile.am +++ b/babl/base/Makefile.am @@ -1,3 +1,4 @@ + h_sources = \ babl-base.h @@ -6,6 +7,7 @@ c_sources = \ type-float.c \ type-u8.c \ type-u16.c \ + type-u32.c \ model-rgb.c \ model-gray.c \ model-ycbcr.c diff --git a/babl/base/babl-base.c b/babl/base/babl-base.c index 12165b4..38cf6d6 100644 --- a/babl/base/babl-base.c +++ b/babl/base/babl-base.c @@ -46,6 +46,7 @@ babl_base_destroy (void) void babl_base_type_float (void); void babl_base_type_u8 (void); void babl_base_type_u16 (void); +void babl_base_type_u32 (void); static void types (void) @@ -53,6 +54,7 @@ types (void) babl_base_type_float (); babl_base_type_u8 (); babl_base_type_u16 (); + babl_base_type_u32 (); } /* diff --git a/babl/base/type-float.c b/babl/base/type-float.c index 0f23f22..7881b8f 100644 --- a/babl/base/type-float.c +++ b/babl/base/type-float.c @@ -67,14 +67,14 @@ babl_base_type_float (void) babl_conversion_new ( babl_type_id (BABL_FLOAT), babl_type_id (BABL_DOUBLE), - "linear", convert_float_double, + "plane", convert_float_double, NULL ); babl_conversion_new ( babl_type_id (BABL_DOUBLE), babl_type_id (BABL_FLOAT), - "linear", convert_double_float, + "plane", convert_double_float, NULL ); } diff --git a/babl/base/type-u16.c b/babl/base/type-u16.c index 170b357..e33997e 100644 --- a/babl/base/type-u16.c +++ b/babl/base/type-u16.c @@ -18,6 +18,7 @@ */ #include +#include #include #include "babl.h" @@ -25,20 +26,20 @@ static inline long -convert_double_u16_scaled (double min_val, - double max_val, - unsigned short min, - unsigned short max, - void *src, - void *dst, - int src_pitch, - int dst_pitch, - long n) +convert_double_u16_scaled (double min_val, + double max_val, + uint16_t min, + uint16_t max, + void *src, + void *dst, + int src_pitch, + int dst_pitch, + long n) { while (n--) { - double dval = *(double *) src; - unsigned short u16val; + double dval = *(double *) src; + uint16_t u16val; if (dval < min_val) u16val = min; @@ -47,7 +48,7 @@ convert_double_u16_scaled (double min_val, else u16val = (dval-min_val) / (max_val-min_val) * (max-min) + min; - *(unsigned short *) dst = u16val; + *(uint16_t *) dst = u16val; dst += dst_pitch; src += src_pitch; } @@ -55,19 +56,19 @@ convert_double_u16_scaled (double min_val, } static inline long -convert_u16_double_scaled (double min_val, - double max_val, - unsigned short min, - unsigned short max, - void *src, - void *dst, - int src_pitch, - int dst_pitch, - long n) +convert_u16_double_scaled (double min_val, + double max_val, + uint16_t min, + uint16_t max, + void *src, + void *dst, + int src_pitch, + int dst_pitch, + long n) { while (n--) { - int u16val = *(unsigned short*) src; + int u16val = *(uint16_t*) src; double dval; if (u16val < min) @@ -106,7 +107,7 @@ convert_double_##name (void *src, \ src, dst, src_pitch, dst_pitch, n);\ } -MAKE_CONVERSIONS(u16,0.0,1.0,0,0xffff); +MAKE_CONVERSIONS(u16,0.0,1.0,0,UINT16_MAX); void babl_base_type_u16 (void) @@ -120,14 +121,14 @@ babl_base_type_u16 (void) babl_conversion_new ( babl_type_id (BABL_U16), babl_type_id (BABL_DOUBLE), - "linear", convert_u16_double, + "plane", convert_u16_double, NULL ); babl_conversion_new ( babl_type_id (BABL_DOUBLE), babl_type_id (BABL_U16), - "linear", convert_double_u16, + "plane", convert_double_u16, NULL ); } diff --git a/babl/base/type-u32.c b/babl/base/type-u32.c new file mode 100644 index 0000000..94a4c09 --- /dev/null +++ b/babl/base/type-u32.c @@ -0,0 +1,133 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include + +#include "babl.h" +#include "babl-ids.h" + +static inline long +convert_double_u32_scaled (double min_val, + double max_val, + uint32_t min, + uint32_t max, + void *src, + void *dst, + int src_pitch, + int dst_pitch, + long n) +{ + while (n--) + { + double dval = *(double *) src; + uint32_t u32val; + + if (dval < min_val) + u32val = min; + else if (dval > max_val) + u32val = max; + else + u32val = (dval-min_val) / (max_val-min_val) * (max-min) + min; + + *(uint32_t *) dst = u32val; + dst += dst_pitch; + src += src_pitch; + } + return n; +} + +static inline long +convert_u32_double_scaled (double min_val, + double max_val, + uint32_t min, + uint32_t max, + void *src, + void *dst, + int src_pitch, + int dst_pitch, + long n) +{ + while (n--) + { + int u32val = *(uint32_t*) src; + double dval; + + if (u32val < min) + dval = min_val; + else if (u32val > max) + dval = max_val; + else + dval = (u32val-min) / (double)(max-min) * (max_val-min_val) + min_val; + + (*(double *) dst) = dval; + dst += dst_pitch; + src += src_pitch; + } + return n; +} + +#define MAKE_CONVERSIONS(name, min_val, max_val, min, max) \ +static long \ +convert_##name##_double (void *src, \ + void *dst, \ + int src_pitch, \ + int dst_pitch, \ + long n) \ +{ \ + return convert_u32_double_scaled (min_val, max_val, min, max, \ + src, dst, src_pitch, dst_pitch, n);\ +} \ +static long \ +convert_double_##name (void *src, \ + void *dst, \ + int src_pitch, \ + int dst_pitch, \ + long n) \ +{ \ + return convert_double_u32_scaled (min_val, max_val, min, max, \ + src, dst, src_pitch, dst_pitch, n);\ +} + +MAKE_CONVERSIONS(u32,0.0,1.0,0,UINT32_MAX); + +void +babl_base_type_u32 (void) +{ + babl_type_new ( + "u32", + "id", BABL_U32, + "bits", 32, + NULL); + + babl_conversion_new ( + babl_type_id (BABL_U32), + babl_type_id (BABL_DOUBLE), + "plane", convert_u32_double, + NULL + ); + + babl_conversion_new ( + babl_type_id (BABL_DOUBLE), + babl_type_id (BABL_U32), + "plane", convert_double_u32, + NULL + ); +} diff --git a/babl/base/type-u8.c b/babl/base/type-u8.c index f802fa9..c874dfb 100644 --- a/babl/base/type-u8.c +++ b/babl/base/type-u8.c @@ -142,13 +142,13 @@ babl_base_type_u8 (void) babl_conversion_new ( babl_type_id (BABL_U8), babl_type_id (BABL_DOUBLE), - "linear", convert_u8_double, + "plane", convert_u8_double, NULL ); babl_conversion_new ( babl_type_id (BABL_DOUBLE), babl_type_id (BABL_U8), - "linear", convert_double_u8, + "plane", convert_double_u8, NULL ); @@ -156,26 +156,26 @@ babl_base_type_u8 (void) babl_conversion_new ( babl_type_id (BABL_U8_LUMA), babl_type_id (BABL_DOUBLE), - "linear", convert_u8_luma_double, + "plane", convert_u8_luma_double, NULL ); babl_conversion_new ( babl_type_id (BABL_DOUBLE), babl_type_id (BABL_U8_LUMA), - "linear", convert_double_u8_luma, + "plane", convert_double_u8_luma, NULL ); babl_conversion_new ( babl_type_id (BABL_U8_CHROMA), babl_type_id (BABL_DOUBLE), - "linear", convert_u8_chroma_double, + "plane", convert_u8_chroma_double, NULL ); babl_conversion_new ( babl_type_id (BABL_DOUBLE), babl_type_id (BABL_U8_CHROMA), - "linear", convert_double_u8_chroma, + "plane", convert_double_u8_chroma, NULL ); } diff --git a/extensions/CIE-Lab.c b/extensions/CIE-Lab.c index dd90b76..f00710a 100644 --- a/extensions/CIE-Lab.c +++ b/extensions/CIE-Lab.c @@ -407,26 +407,26 @@ types_u8 (void) babl_conversion_new ( babl_type ("CIE u8 L"), babl_type ("double"), - "linear", convert_u8_l_double, + "plane", convert_u8_l_double, NULL ); babl_conversion_new ( babl_type ("double"), babl_type ("CIE u8 L"), - "linear", convert_double_u8_l, + "plane", convert_double_u8_l, NULL ); babl_conversion_new ( babl_type ("CIE u8 ab"), babl_type ("double"), - "linear", convert_u8_ab_double, + "plane", convert_u8_ab_double, NULL ); babl_conversion_new ( babl_type ("double"), babl_type ("CIE u8 ab"), - "linear", convert_double_u8_ab, + "plane", convert_double_u8_ab, NULL ); } @@ -547,26 +547,26 @@ types_u16 (void) babl_conversion_new ( babl_type ("CIE u16 L"), babl_type ("double"), - "linear", convert_u16_l_double, + "plane", convert_u16_l_double, NULL ); babl_conversion_new ( babl_type ("double"), babl_type ("CIE u16 L"), - "linear", convert_double_u16_l, + "plane", convert_double_u16_l, NULL ); babl_conversion_new ( babl_type ("CIE u16 ab"), babl_type ("double"), - "linear", convert_u16_ab_double, + "plane", convert_u16_ab_double, NULL ); babl_conversion_new ( babl_type ("double"), babl_type ("CIE u16 ab"), - "linear", convert_double_u16_ab, + "plane", convert_double_u16_ab, NULL ); } diff --git a/extensions/Makefile.in b/extensions/Makefile.in index 3e80757..054f163 100644 --- a/extensions/Makefile.in +++ b/extensions/Makefile.in @@ -20,6 +20,8 @@ CFLAGS += -Wall CIE-Lab.so: CIE-Lab.c $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lm +lcms.so: lcms.c + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< `pkg-config lcms --cflags --libs` @@ -51,6 +53,7 @@ distdir: cp $(CFILES) $(Makefile.in) $$distdir dvi: +check: #playing along with automake .PRECIOUS: Makefile diff --git a/tests/Makefile.am b/tests/Makefile.am index 71b7509..b55612c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -9,8 +9,10 @@ TESTS = \ rgb_to_ycbcr \ srgb_to_lab_u8 \ sanity \ + conversions \ types \ models \ + foo \ babl_class_name TESTS_ENVIRONMENT = BABL_PATH=$(top_builddir)/extensions @@ -23,6 +25,7 @@ babl_class_name_SOURCES = babl_class_name.c sanity_SOURCES = sanity.c types_SOURCES = types.c models_SOURCES = models.c +foo_SOURCES = foo.c AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl diff --git a/tests/conversions.c b/tests/conversions.c new file mode 100644 index 0000000..f8703bd --- /dev/null +++ b/tests/conversions.c @@ -0,0 +1,172 @@ +/* perform a symmetricality of conversion test on a set of randomized + * RGBA data */ + +#include +#include +#include "babl-internal.h" + +int OK=1; + +#define pixels 102400 +#define TOLERANCE 0.001 + +double test[pixels * 4]; + +double r_interval (double min, double max) +{ + long int rand_i = random (); + double ret; + ret = (double) rand_i / RAND_MAX; + ret*=(max-min); + ret+=min; + return ret; +} + +void test_init (void) +{ + double r_min = 0.0, + r_max = 1.0, + g_min = 0.0, + g_max = 1.0, + b_min = 0.0, + b_max = 1.0, + a_min = 0.0, + a_max = 1.0; + int i; + double r,g,b,a; + for (i=0;isource); + Babl *fmt_destination = BABL(conversion->destination); + + void *source; + void *destination; + double *destination_rgba_double; + void *ref_destination; + double *ref_destination_rgba_double; + + source = babl_calloc (pixels, fmt_source->format.bytes_per_pixel); + destination = babl_calloc (pixels, fmt_destination->format.bytes_per_pixel); + ref_destination = babl_calloc (pixels, fmt_destination->format.bytes_per_pixel); + destination_rgba_double = babl_calloc (pixels, fmt_rgba_double->format.bytes_per_pixel); + ref_destination_rgba_double = babl_calloc (pixels, fmt_rgba_double->format.bytes_per_pixel); + + babl_process (babl_fish_reference (fmt_rgba_double, fmt_source), + test, source, pixels); + babl_process (babl_fish_simple (conversion), + source, destination, pixels); + + babl_process (babl_fish_reference (fmt_source, fmt_destination), + source, ref_destination, pixels); + + babl_process (babl_fish_reference (fmt_destination, fmt_rgba_double), + ref_destination, ref_destination_rgba_double, pixels); + babl_process (babl_fish_reference (fmt_destination, fmt_rgba_double), + destination, destination_rgba_double, pixels); + + { + int i; + int log=0; + + for (i=0;iTOLERANCE) + { + if (!log) + log=1; + OK=0; + } + if (log && log < 5) + { + babl_log ("%s", conversion->instance.name); + babl_log ("\ttest: %2.3f %2.3f %2.3f %2.3f", test [i*4+0], + test [i*4+1], + test [i*4+2], + test [i*4+3]); + babl_log ("\tconversion: %2.3f %2.3f %2.3f %2.3f", destination_rgba_double [i*4+0], + destination_rgba_double [i*4+1], + destination_rgba_double [i*4+2], + destination_rgba_double [i*4+3]); + babl_log ("\tref_conversion: %2.3f %2.3f %2.3f %2.3f", ref_destination_rgba_double [i*4+0], + ref_destination_rgba_double [i*4+1], + ref_destination_rgba_double [i*4+2], + ref_destination_rgba_double [i*4+3]); + log++; + OK=0; + } + } + } + + + babl_free (source); + babl_free (destination); + babl_free (destination_rgba_double); + babl_free (ref_destination); + babl_free (ref_destination_rgba_double); +} + +static int +each_conversion (Babl *babl, + void *userdata) +{ + Babl *source = BABL(babl->conversion.source); + Babl *destination = BABL(babl->conversion.destination); + + if (source->instance.id != BABL_RGBA && + destination->instance.id != BABL_RGBA && + source->instance.id != BABL_DOUBLE && + destination->instance.id != BABL_DOUBLE && + source->class_type == BABL_FORMAT && + destination->class_type == BABL_FORMAT) + { + validate_conversion ((BablConversion*)babl); + } + return 0; +} + +int main (void) +{ + babl_init (); + test_init (); + + babl_set_extender (babl_extension_quiet_log ()); + babl_conversion_each (each_conversion, NULL); + + babl_destroy (); + + return !OK; +} -- 2.30.2